package homework.day07;

import java.util.Scanner;

public class CalAirPrice {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入飞机票价格：");
        double price = scan.nextDouble();
        System.out.println("请输入月份：");
        int month = scan.nextInt();
        System.out.println("请输入(只输入数字编号即可)：1头等舱 2商务舱 3经济舱");
        int type = scan.nextInt();

        //--------------1
        double finalPrice = calFinalPrice(price,month,type);
        if(finalPrice!=-1){
            System.out.println("飞机票打折后价格为："+finalPrice);
        }
        //--------------2
        boolean flag = checkValue(price,month,type);
        if(flag){
            finalPrice = getFinalPrice(price,month,type);
            System.out.println("飞机票折后价格为："+finalPrice);
        }else{
            System.out.println("写入数据错误");
        }

    }

    public static boolean checkValue(double price,int month,int type){
        return price>=0 && month>=1 && month<=12 && type>=1 && type<=3;
    }

    public static double getFinalPrice(double price,int month,int type){
        double finalPrice = 0.0;
        if(month>=5 && month<=10){
            switch (type){
                case 1:finalPrice = price*0.9;break;
                case 2:finalPrice = price*0.85;break;
                case 3:finalPrice = price*0.8;
            }
        }else{
            switch (type){
                case 1:finalPrice = price*0.7;break;
                case 2:finalPrice = price*0.65;break;
                case 3:finalPrice = price*0.6;
            }
        }
        return finalPrice;
    }


    public static double calFinalPrice(double price,int month,int type){
        double finalPrice = 0.0;
        if(price<0){
            System.out.println("价格输入错误");
            return -1;
        }
        if(month<1 || month>12){
            System.out.println("月份输入错误");
            return -1;
        }
        if(type<1 || type>3){
            System.out.println("舱类错误");
            return -1;
        }
        if(month>=5 && month<=10){
            switch (type){
                case 1:
                    finalPrice = price*0.9;
                    break;
                case 2:
                    finalPrice = price*0.85;
                    break;
                case 3:
                    finalPrice = price*0.8;
            }
        }else{
            switch (type){
                case 1:
                    finalPrice = price*0.7;
                    break;
                case 2:
                    finalPrice = price*0.65;
                    break;
                case 3:
                    finalPrice = price*0.6;
            }
        }
        return finalPrice;
    }
}
